<template>
    <el-dialog v-if="dialogVisible" :close-on-click-modal='false' title="项目信息" :visible.sync="dialogVisible" @close="resetForm('editForm')" width="400px">
        <el-form label-position="top" :model="editForm" :hide-required-asterisk='true' ref="editForm" :rules="addBrandRules" class="dialog_form">
            <el-form-item label="需求总数" prop="quantity">
                <el-input v-model="editForm.quantity" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="分组" prop="group">
                <el-select v-model="editForm.group" placeholder="请选择分组" style="width:100%">
                    <el-option label="1 组" :value="1"></el-option>
                    <el-option label="2 组" :value="2"></el-option>
                    <el-option label="3 组" :value="3"></el-option>
                    <el-option label="4 组" :value="4"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('editForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('editForm')" :disabled="loading" :loading="loading" class="el-button-width">确 认</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    props:["queryInfo"],
    name: "",
    data() {
        return {
            loading: false,
            dialogVisible: false,
            editForm: {
                id:"",
                year:"",
                week:"",
                quantity: "",
                group: "",
            },
            addBrandRules: {
                quantity: [
                    {
                        required: true,
                        message: "请输入需求总数",
                        trigger: ["blur", "change"],
                    },
                ],
            },
        };
    },
    created() {},
    methods: {
        getData(row){
            let data = JSON.parse(JSON.stringify(row))
            this.dialogVisible = true
            this.editForm.id = data.id
            this.editForm.year = data.year
            this.editForm.week = data.week
            this.editForm.quantity = data.quantity
            this.editForm.group = data.group
        },
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "adminapi/demandsz/demandProjectEdit",
                        this.editForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "保存成功",
                            type: "success",
                        });
                        this.loading = false;
                        this.resetForm(formName);
                        this.$emit("getDataList",this.queryInfo.page)
                        this.$emit("getDataCount")
                        this.$emit("getStatistics");
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
    components: {},
};
</script>


<style scoped>
</style>
